home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-21 | 10.0 KB | 369 lines |
- /* $Id: CtrlPanel.java,v 1.4 1996/03/31 11:43:02 djun Exp djun $
-
- File: CtrlPanel.java
-
- Author: Djun M. Kim
- Copyright (c) 1996 Djun M. Kim. All rights reserved.
-
- Notes:
-
- Things to do:
-
- * Add the ability to work with and display multiple selections in
- the list.
-
- * Internationalization support - labels and text displayed via
- arrays of unicode strings indexed by language.
-
- */
-
- import java.awt.*;
- import java.net.*;
- import java.util.*;
-
- public class CtrlPanel extends gridPanel {
-
- // our parent...
- MapInfo parent;
-
- private int panelFunction; // What is the MapPanel doing for the user?
-
- private static int numFuncs = 4; // number of different fns
- private String fnName[] = // ... and their names.
- {"Information",
- "Route Info",
- "Detail maps",
- "Search"};
-
- // Constants
- final int getLocationInfo = 0; // Enumeration of function
- final int getRouteInfo = 1; // by symbolic name
- final int getDetailInfo = 2;
- final int getSearchInfo = 3;
-
- private CheckboxGroup fngrp = new CheckboxGroup();
- public Checkbox cb_loc = new Checkbox(fnName[getLocationInfo], fngrp, true);
- public Checkbox cb_route = new Checkbox(fnName[getRouteInfo], fngrp, false);
- public Checkbox cb_detail = new Checkbox(fnName[getDetailInfo], fngrp, false);
- public Checkbox cb_search = new Checkbox(fnName[getSearchInfo], fngrp, false);
-
- final int REMN = GridBagConstraints.REMAINDER;
-
- Panel fnctn = new Panel(); // panel for selecting function
- Panel display = new Panel(); // cardpanel for user function interaction
-
- CardLayout display_layout = new CardLayout();
-
- InfoPane info_display; // panels for various user functions
- RoutePane route_display;
- DetailPane detail_display;
- SearchPane search_display;
-
- // Constructor
-
- CtrlPanel(MapInfo target) {
- super(target);
- c.insets = new Insets(5, 5, 0, 5);
- // Get a hold of our parent...
- this.parent = target;
- display.setLayout(display_layout);
- makeControls ();
- }
-
- // Top-level control panel
- void makeControls (){
- // Panel gridx gridy Weightx Weighty GridW GridH
- make_panel(fnctn, 1, 1, 1.0, 0.0, REMN, 1);
- make_panel(display, 1, 2, 1.0, 1.0, REMN, REMN);
- // add radio buttons
- fnctn.setLayout(new GridLayout(3, 2));
- fnctn.add(cb_loc);
- fnctn.add(cb_route);
- fnctn.add(cb_detail);
- fnctn.add(cb_search);
-
- info_display = new InfoPane("info_display", display, parent);
- route_display = new RoutePane(display, parent);
- detail_display = new DetailPane(display, parent);
- search_display = new SearchPane("search_display", display, parent);
- }
-
- // Event handler
- public boolean action(Event evt, Object arg) {
- if (evt.target instanceof Checkbox) {
- Checkbox cb = (Checkbox)evt.target;
- String cbox_seln = cb.getLabel();
- if (cbox_seln == fnName[getLocationInfo]) {
- panelFunction = getLocationInfo;
- parent.setInfo("Show information about selected location");
- display_layout.show(display, "info_display");
- } else
- if (cbox_seln == fnName[getRouteInfo]) {
- panelFunction = getRouteInfo;
- parent.setInfo("Show route information");
- display_layout.show(display, "route_display");
- } else
- if (cbox_seln == fnName[getDetailInfo]) {
- panelFunction = getDetailInfo;
- parent.setInfo("Show detailed map");
- display_layout.show(display, "detail_display");
- } else
- if (cbox_seln == fnName[getSearchInfo]) {
- panelFunction = getSearchInfo;
- parent.setInfo("Search for location");
- display_layout.show(display, "search_display");
- } else // default:
- {
- panelFunction = getLocationInfo;
- parent.setInfo("Show information about selected location");
- display_layout.show(display, "info_display");
- }
- return true;
- } else
- return false;
- }
-
- // returns the current user function of the Map panel
- public int getPanelFunction(){
- return panelFunction;
- };
-
- // set the current user function of the Map panel
- public void setPanelFunction(int function){
- panelFunction = function;
- switch (function) {
- case getLocationInfo:
- cb_loc.setState(true);
- break;
- case getRouteInfo:
- cb_route.setState(true);
- break;
- case getDetailInfo:
- cb_detail.setState(true);
- break;
- case getSearchInfo:
- cb_search.setState(true);
- };
- };
-
- void showCoords(int x, int y) {
- parent.setInfo("X: " + x + ", Y: " + y);
- }
- }
-
- class InfoPane extends gridPanel {
- // Information display panel
-
- MapInfo parent;
-
- TextField namefield;
- TextField basefield;
- TextField urlfield;
- Button show_url;
- TextArea infofield;
-
- InfoPane(String label, Container target, MapInfo parent) {
- super(label, target);
- this.parent = parent;
- // Name WeightX WeightY gridW gridH
- Label name =
- make_label("Name:", 0.0, 0.0, 1, 1);
- namefield =
- make_textf("Click on map to see name", false,
- 0.6, 0.0, REMN, 1);
- Label base =
- make_label("Base Coords:", 0.0, 0.0, 1, 1);
- basefield =
- make_textf(" ", false, 0.6, 0.0, REMN, 1);
- show_url =
- make_button("Show URL", 0.0, 0.0, 1, 1);
- urlfield =
- make_textf(" ", false, 0.6, 0.0, REMN, 1);
- infofield =
- make_texta(" ", 8, 20, 1.0, 1.0, REMN, REMN);
- }
-
- public void showLocationName(String s) {
- namefield.setText(s);
- }
-
- public void showLocationBase(Point p) {
- if (p != null) {
- basefield.setText("x:"+p.x+", y:"+p.y);
- } else {
- basefield.setText(" ");
- }
- }
-
- public void showLocationURL(URL url) {
- if (url != null) {
- urlfield.setText(url.toString());
- } else {
- urlfield.setText(" ");
- }
- }
-
- public void showLocationInfoText(String s) {
- if (s != null) {
- infofield.setText(s);
- } else {
- // Setting text to the empty string doesn't clear the old text!
- infofield.setText(" ");
- }
- }
-
- // Clear the information panel.
- public void clearLocationInfo(){
- //parent.error_handler.debug("Clearing info.");
- showLocationName(" ");
- showLocationBase(null);
- showLocationURL(null);
- showLocationInfoText(" ");
- }
-
- // Show information about the Location with base coordinates (x, y)
- public void showLocationInfo(int x, int y) {
- Location loc = parent.map.getLocation(x,y);
- clearLocationInfo();
- if (loc != null) {
- showLocationName(loc.getName());
- showLocationBase(loc.getBase());
- showLocationURL(loc.getURL());
- showLocationInfoText(loc.getInfoText());
- }
- }
-
- // Event handler
- public boolean action(Event evt, Object arg) {
- if (evt.target instanceof Button) {
- if (((Button)evt.target) == show_url) {
- Location loc = (Location)parent.mapview.canvas.getSelectedLocation();
- if (loc != null) {
- gotoURL(loc.getURL());
- }
- }
- return true;
- } else
- return false;
- }
-
- public void gotoURL(URL url) {
- if (url != null)
- parent.getAppletContext().showDocument(url);
- }
- }
-
-
- class SearchPane extends gridPanel {
- // Location search display panel
-
- MapInfo parent;
-
- Label searchfor;
- TextField search_entry;
- List locn_list;
- Button show_info;
-
- SearchPane(String label, Panel target, MapInfo parent) {
- super(label, target);
- this.parent = parent;
-
- // Name WeightX WeightY gridW gridH
- Label searchfor =
- make_label("Search For:", 0.0, 0.0, 1, 1 );
- search_entry =
- make_textf("Location", true,
- 1.0, 0.0, REMN, 1 );
- locn_list =
- make_list(" ", 7, false, 1.0, 1.0, REMN, 1 );
- show_info =
- make_button(" Show selection ",
- 1.0, 0.0, REMN, 1 );
- }
-
- // Event handler
- public boolean action(Event evt, Object arg) {
-
- SearchPane s = parent.ctrlview.search_display;
- InfoPane info = parent.ctrlview.info_display;
-
- if (evt.target instanceof TextField) {
- TextField tf = (TextField)evt.target;
- if (tf == search_entry) {
- searchEntry(tf.getText());
- }
- return true;
- } else if (evt.target instanceof List) {
- List list = (List)evt.target;
- if (list.getSelectedItem() != null) {
- // get the location
- Location loc = parent.map.getLocationByName(list.getSelectedItem());
- // select the location on the Map
- parent.mapview.canvas.setSelectedLocation(loc);
- parent.mapview.canvas.repaint();
- // set a the button to offer to display more info...
- Button b = parent.ctrlview.search_display.show_info;
- b.setLabel("Show info for "+list.getSelectedItem());
- }
- return true;
- } else if (evt.target instanceof Button) {
- Button b = (Button)evt.target;
- // b.setLabel("Show info for "+s.locn_list.getSelectedItem());
- if (s.locn_list.getSelectedItem() != null) {
- if (b == parent.ctrlview.search_display.show_info) {
- Location loc = parent.map.getLocationByName(s.locn_list.getSelectedItem());
- //parent.error_handler.debug("Selected location = "+loc.getName());
- //parent.error_handler.debug("X:"+loc.getBase().x+", Y:"+loc.getBase().y);
- parent.ctrlview.display_layout.show(
- (Container)parent.ctrlview.display,"info_display");
- parent.ctrlview.setPanelFunction(parent.ctrlview.getLocationInfo);
- info.showLocationInfo(loc.getBase().x, loc.getBase().y);
- }
- }
- return true;
- } else
- return false;
- }
-
- // Handle searching for locations
- public void searchEntry(String s) {
- Vector matchingLocns;
- parent.setInfo("Searching for locations matching "+s+"...");
- matchingLocns = parent.map.findLocationsByKeyword(s);
- locn_list.clear();
- if (matchingLocns != null) {
- int count = 0;
- for (Enumeration e = matchingLocns.elements();
- e.hasMoreElements(); ) {
- Location loc = (Location)e.nextElement();
- locn_list.addItem(loc.getName());
- count++;
- }
- parent.setInfo("Found "+count+" locations matching "+s+".");
- } else {
- parent.setInfo("No locations matched "+s+".");
- }
- }
- }
-
- // Route display panel
- class RoutePane extends Panel {
-
- RoutePane(Panel target, MapInfo parent) {
- target.add("route_display", this);
- setLayout(new GridLayout(1,1));
- add(new Button("Routes"));
- }
- }
-
- // Detail display panel
- class DetailPane extends Panel {
-
- DetailPane(Panel target, MapInfo parent) {
- target.add("detail_display", this);
- setLayout(new GridLayout(1,1));
- add(new Button("Show location details"));
- }
- }
-
-